import allure
from appium.webdriver.common.appiumby import AppiumBy

from tests.app.pages.wecom import Wecom


class QueryPage(Wecom):
    __QUERY_INPUT = AppiumBy.ID, 'com.tencent.wework:id/klw'
    __QUERY_PERSON = AppiumBy.XPATH, '//*[@text="联系人" and @class="android.widget.TextView"]'
    __QUERY_GROUP = AppiumBy.XPATH, '//*[@text="群聊" and @class="android.widget.TextView"]'
    __QUERY_CHAT_HISTORY = AppiumBy.XPATH, '//*[@text="聊天记录" and @class="android.widget.TextView"]'
    __QUERY_EMAIL = AppiumBy.XPATH, '//*[@text="邮件" and @class="android.widget.TextView"]'
    __QUERY_FILE = AppiumBy.XPATH, '//*[@text="文档" and @class="android.widget.TextView"]'
    __QUERY_SCHEDULE = AppiumBy.XPATH, '//*[@text="日程" and @class="android.widget.TextView"]'
    __QUERY_MICRODISK = AppiumBy.XPATH, '//*[@text="微盘" and @class="android.widget.TextView"]'
    __QUERY_APPLICATION = AppiumBy.XPATH, '//*[@text="应用" and @class="android.widget.TextView"]'
    __QUERY_APPLICATION_WARN = AppiumBy.XPATH, '//*[@text="应用提醒" and @class="android.widget.TextView"]'
    __QUERY_EXAMINE = AppiumBy.XPATH, '//*[@text="审批" and @class="android.widget.TextView"]'
    __QUERY_COLLECTION = AppiumBy.XPATH, '//*[@text="收藏" and @class="android.widget.TextView"]'

    def query_input(self, text):
        self.find_and_send(*self.__QUERY_INPUT, text)
        return self
    @allure.step("查找联系人")
    def query_person(self):
        self.find_and_click(*self.__QUERY_PERSON)
        return self
    @allure.step("查找群组")
    def query_group(self):
        self.find_and_click(*self.__QUERY_GROUP)
        return self
    @allure.step("查找聊天记录")
    def query_chat_history(self):
        self.find_and_click(*self.__QUERY_CHAT_HISTORY)
        return self
    @allure.step("查找邮件")
    def query_email(self):
        self.find_and_click(*self.__QUERY_EMAIL)
        return self
    @allure.step("查找文档")
    def query_file(self):
        self.find_and_click(*self.__QUERY_FILE)
        return self
    @allure.step("横向滑动")
    def lateral_sliding(self, duration=2000):
        size = self.driver.get_window_size()
        height = size.get('height')
        weight = size.get('width')
        start_x = weight * 0.8
        start_y = height * 0.17
        end_x = weight * 0.2
        end_y = height * 0.17
        self.driver.swipe(start_x, start_y, end_x, end_y, duration)
    @allure.step("查找日程")
    def query_schedule(self):
        self.lateral_sliding()
        self.find_and_click(*self.__QUERY_SCHEDULE)
        return self
    @allure.step("查找微盘")
    def query_microdisk(self):
        self.lateral_sliding()
        self.find_and_click(*self.__QUERY_MICRODISK)
        return self
    @allure.step("查找应用")
    def query_application(self):
        self.lateral_sliding()
        self.find_and_click(*self.__QUERY_APPLICATION)
        return self
    @allure.step("查找应用提醒")
    def query_application_warn(self):
        self.lateral_sliding()
        self.find_and_click(*self.__QUERY_APPLICATION_WARN)
        return self
    @allure.step("查找审批")
    def query_examine(self):
        self.lateral_sliding()
        self.find_and_click(*self.__QUERY_EXAMINE)
        return self
    @allure.step("查找收藏")
    def query_collection(self):
        self.lateral_sliding()
        self.find_and_click(*self.__QUERY_COLLECTION)
        return self